package com.example.demo.api;

import com.example.demo.model.Result;
import com.example.demo.param.PaymentParam;
import com.example.demo.service.PayService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/api/alipay")
public class PaymentAPI {

    @Autowired
    private PayService payService;

    @RequestMapping("/pay")
    @ResponseBody
    public Result payOrder(@RequestBody PaymentParam paymentParam) {
        Result result = new Result();
        result.setSuccess(true);
        if (StringUtils.isEmpty(paymentParam.getUserId())) {
            result.setSuccess(false);
            result.setMessage("userId is null");
            return result;
        }
        if (paymentParam.getPayAmount() <= 0) {
            result.setMessage("支付金额不能小于0");
            return result;
        }
        return payService.payOrder(paymentParam);
    }
}
